﻿@model OrderModel

@using Urs.Data.Domain.Stores;
@using Urs.Data.Domain.Payments


<style type="text/css">
    .laytable-cell-1-PictureThumbnailUrl, .laytable-cell-2-PictureThumbnailUrl {
        height: 100%;
        max-width: 100%;
    }
</style>

<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header layuiadmin-card-header-auto">
                    订单信息 <a href="javascript:;" layadmin-event="back">返回</a>
                </div>
                <div class="layui-card-body">
                    <fieldset class="layui-elem-field">
                        <legend>订单状态-[@Model.OrderStatus]</legend>
                        <div class="layui-field-box">
                            <div class="layui-card-body layui-row layui-form">
                                <div class="layui-col-md12">
                                    <input asp-for="Id" type="hidden" />
                                    <u-label asp-for="Id" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Html.Raw(Model.Id)  （GUID:@Html.Raw(Model.OrderGuid)）
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <u-label asp-for="UserId" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @string.Format("{0}  {1}", Model.UserId, Model.UserFullName)
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <u-label asp-for="OrderTotal" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Model.OrderTotal
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">
                                        [其中商品小计:@Model.OrderSubtotalValue  配送费:@Model.OrderShippingValue ]
                                    </div>
                                </div>
                                @if (Model.RedeemedRewardPoints > 0)
                                {
                                    <div class="layui-col-md12">
                                        <u-label asp-for="RedeemedRewardPoints" />
                                        <div class="layui-form-mid layui-word-aux">
                                            @Model.RedeemedRewardPoints @T("Admin.Orders.Fields.RedeemedRewardPoints.Points")
                                            @Model.RedeemedRewardPointsAmount
                                        </div>
                                    </div>
                                }
                                <div class="layui-col-md12">
                                    <u-label asp-for="PaymentMethod" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Model.PaymentMethod
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <u-label asp-for="PaymentStatus" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Model.PaymentStatus
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <u-label asp-for="Remark" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Model.Remark
                                    </div>
                                </div>
                                <div class="layui-col-md12">
                                    <u-label asp-for="CreateTime" />
                                    <div class="layui-form-mid layui-word-aux">
                                        @Model.CreateTime
                                    </div>
                                </div>
                                <script>
                                        layui.config({
                                            base: '../../../layuiadmin/' //静态资源所在路径
                                        }).extend({
                                            index: 'lib/index' //主入口模块
                                        }).use(['index','table'], function () {
                                            var table = layui.table
                                                , form = layui.form;

                                            var $ = layui.$, active = {
                                                markpaid: function () {
                                                    layer.confirm('确认为已付款？', function (index) {
                                                        $.post('/admin/order/markorderaspaid/@Model.Id', {}, function (data) {
                                                            if (data.success) {
                                                                layer.msg('订单确认付款成功');
                                                            } else {
                                                                layer.msg(data.msg);
                                                            }
                                                            layer.close(index);
                                                        });
                                                    });

                                                },
                                                cancelorder: function () {
                                                   layer.confirm('确认取消订单？', function (index) {
                                                    $.post('/admin/order/cancelorder/@Model.Id', {}, function (data) {
                                                        if (data.success) {
                                                            layer.msg('取消订单成功');
                                                        } else {
                                                            layer.msg(data.msg);
                                                        }
                                                            layer.close(index);
                                                        });
                                                    });
                                                },
                                                deleteorder: function () {
                                                   layer.confirm('确认删除订单？', function (index) {
                                                       $.post('/admin/order/delete/@Model.Id', {}, function (data) {
                                                        if (data.success) {
                                                            layer.msg('删除订单成功');
                                                        } else {
                                                            layer.msg(data.msg);
                                                        }
                                                            layer.close(index);
                                                        });
                                                    });
                                                },
                                                modifyprice: function () {
                                                    var index = layer.open({
                                                        type: 2
                                                        , title: '修改订单金额'
                                                        , content:  '@Url.Action("ModifyPrice",new { id=Model.Id})'
                                                        , area: ['450px', '380px']
                                                        , btn: ['确定', '取消']
                                                        , yes: function (index, layero) {
                                                            //点击确认触发 iframe 内容中的按钮提交
                                                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                                            submit.click();
                                                        }
                                                    });
                                                }
                                            }

                                            $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
                                                var type = $(this).data('type');
                                                active[type] ? active[type].call(this) : '';
                                            });
                                        });
                                </script>
                            </div>
                        </div>
                    </fieldset>
                    @if (Model.IsShippable)
                    {
                        <fieldset class="layui-elem-field">
                            <legend>配送信息</legend>
                            <div class="layui-field-box">
                                @if (Model.ShippingAddress != null)
                                {
                                    if (Model.ShippingAddress.NameEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <div class="col-md-2">
                                                <label class="layui-form-label">@T("Admin.Orders.Address.FullName")</label>
                                            </div>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.Name
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.PhoneEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">@T("Admin.Orders.Address.Phone")</label>

                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.PhoneNumber
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.FaxEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">@T("Admin.Orders.Address.Fax")</label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.FaxNumber
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.CompanyEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">
                                                @T("Admin.Orders.Address.Company")
                                            </label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.Company
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.ProvincesEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">
                                                @T("Admin.Orders.Address.Province") @T("Admin.Orders.Address.City")  @T("Admin.Orders.Address.Area")
                                            </label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.ProvinceName
                                                &nbsp;
                                                @Model.ShippingAddress.CityName
                                                &nbsp;
                                                @Model.ShippingAddress.AreaName
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.StreetAddressEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">
                                                @T("Admin.Orders.Address.Address1")
                                            </label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.Address1
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.StreetAddress2Enabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">
                                                @T("Admin.Orders.Address.Address2")
                                            </label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.Address2
                                            </div>
                                        </div>
                                    }
                                    if (Model.ShippingAddress.ZipPostalCodeEnabled)
                                    {
                                        <div class="layui-col-md12">
                                            <label class="layui-form-label">
                                                @T("Admin.Orders.Address.ZipPostalCode")
                                            </label>
                                            <div class="layui-form-mid layui-word-aux">
                                                @Model.ShippingAddress.ZipPostalCode
                                            </div>
                                        </div>
                                    }
                                }
                                else
                                {
                                    <div class="layui-col-md12">
                                        配送信息：
                                        <div class="layui-form-mid layui-word-aux">
                                            暂无
                                        </div>
                                    </div>
                                }
                            </div>
                        </fieldset>
                    }
                    <fieldset class="layui-elem-field">
                        <legend>商品明细</legend>
                        <div class="layui-field-box">
                            <table id="LAY-ordergoods-list" lay-filter="LAY-ordergoods-list" style="width:100%;"></table>
                            <script type="text/html" id="layuiadmin-ordergoods-tagsbar">
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            </script>
                            <script>
                                layui.use(['jquery','index', 'table'], function () {
                                            var index = layer.load(2, { shade: false });
                                                var $ = layui.$
                                                ,table = layui.table
                                                , form = layui.form;
                                        //分类管理
                                        table.render({
                                            elem: '#LAY-ordergoods-list'
                                            , cols: [[
                                                { field: 'Id', width: 100,  title: 'ID' }
                                                , { field: 'PictureThumbnailUrl', width: 100, style: 'height:80px;', title: '图片', templet: '<div><img src={{d.PictureThumbnailUrl}}></div>' }
                                                , { field: 'GoodsName', title: '商品名称', minWidth: 100, templet: '<div>{{d.GoodsName}}{{d.AttributeInfo}}</div>'}
                                                , { field: 'UnitPrice', title: '单价[可修改]', edit: 'text',  width: 150, align: 'center' }
                                                , { field: 'Quantity', title: '数量[可修改]', edit: 'text',  width: 150, align: 'center' }
                                                , { field: 'SubTotal', title: '小计', width: 120, align: 'center' }
                                                , { title: '操作', width: 150, align: 'center', toolbar: '#layuiadmin-ordergoods-tagsbar' }
                                            ]]
                                            , data: [
                                                @for (int i = 0; i < Model.Items.Count; i++)
                                                {
                                                    var item = Model.Items[i];
                                                    <text>
                                                        {
                                                            Id:@(item.Id),
                                                            PictureThumbnailUrl:"@item.PictureThumbnailUrl",
                                                            GoodsName: "@item.GoodsName",
                                                            AttributeInfo: "@item.AttributeInfo",
                                                            Sku:"@item.Sku",
                                                            UnitPrice:"@item.UnitPriceValue",
                                                            Quantity:"@item.Quantity",
                                                            SubTotal:"@item.SubTotal"
                                                        }
                                                    </text>
                                                    if (i != Model.Items.Count - 1)
                                                    {
                                                        <text>,</text>
                                                    }
                                                }
                                                ]
                                            , text: { none: '一条数据也没有^_^' }
                                            , id: 'ordergoods-list'
                                            , done: function () {
                                                layer.close(index);
                                            }
                                        });

                                        //监听单元格编辑
                                        table.on('edit(LAY-ordergoods-list)', function (obj) {
                                            var value = obj.value //得到修改后的值
                                                , data = obj.data //得到所在行所有键值
                                                , field = obj.field; //得到字段

                                            $.post('@Url.Action("EditOrderGoods")', { id:@Model.Id, opId: data.Id, UnitPrice: obj.data.UnitPrice, Quantity: obj.data.Quantity }, function(rep) {
                                                table.reload('ordergoods-list', { page: { curr: 1 } }, 'data');
                                            });
                                        });
                                        //监听工具条
                                        table.on('tool(LAY-ordergoods-list)', function (obj) {
                                            var data = obj.data;
                                            if (obj.event === 'del') {
                                                layer.confirm('确定删除？', function (index) {
                                                    obj.del();
                                                    $.post('@Url.Action("OrderGoodsDelete")', { id: @Model.Id, opId: obj.data.Id });
                                                    layer.close(index);
                                                });
                                            } else if (obj.event === 'edit') {
                                                    layer.open({
                                                        type: 2
                                                            , title: '编辑'
                                                            , content: '@Url.Action("EditOrderGoods")?id=' + data.Id
                                                        , area: ['700px', '500px']
                                                        , btn: ['确定', '取消']
                                                        , yes: function (index, layero) {
                                                            //点击确认触发 iframe 内容中的按钮提交
                                                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                                            submit.click();
                                                        }
                                                    });
                                            }
                                        });
                                });
                            </script>
                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>订单跟踪</legend>
                        <div class="layui-field-box">
                            <table id="LAY-notes-list" lay-filter="LAY-notes-list" style="width:100%;"></table>
                            <script type="text/html" id="layuiadmin-notes-tagsbar">
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            </script>
                            <script>
                                layui.use(['index', 'table'], function () {
                                        var index = layer.load(2, { shade: false });
                                            var $ = layui.$
                                            ,table = layui.table
                                            , form = layui.form;
                                    //分类管理
                                    table.render({
                                        elem: '#LAY-notes-list'
                                        , method: 'post'
                                        , url: '@Html.Raw(Url.Action("OrderNotesSelect", "Order", new {orderId = Model.Id}))'
                                        , cols: [[
                                             { field: 'CreateTime', title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.CreateTime,\'yyyy年MM月dd日 HH:mm\') }}</div>', width: 180 }
                                            , { field: 'Note', title: '提示', minWidth:200 }
                                            , { title: '操作', width: 100, align: 'center', toolbar: '#layuiadmin-notes-tagsbar' }
                                        ]]
                                        , text: { none: '一条数据也没有^_^' }
                                        , done: function () {
                                            layer.close(index);
                                        }
                                    });
                                    //监听工具条
                                    table.on('tool(LAY-notes-list)', function (obj) {
                                        var data = obj.data;
                                        if (obj.event === 'del') {
                                            layer.confirm('确定删除？', function (index) {
                                                obj.del();
                                                $.post('@Url.Action("OrderNoteDelete")', { id:@Model.Id, noteId,obj.data.Id });
                                                layer.close(index);
                                            });
                                        }
                                    });

                                });
                            </script>
                        </div>
                    </fieldset>
                </div>
                <br />
                <br />
                <br />
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-footer" style="left: 0;">
                        @if (Model.CanMarkOrderAsPaid)
                        {
                            <button class="layui-btn layui-btn-warm layuiadmin-btn-tags" data-type="markpaid">确认付款</button>
                        }
                        @if (Model.CanCancelOrder)
                        {
                            <button class="layui-btn layui-btn-primary layuiadmin-btn-tags" data-type="cancelorder">取消订单</button>
                        }
                        @if (Model.PaymentStatusId == (int)PaymentStatus.Pending)
                        {
                            <button class="layui-btn layui-btn-normal layuiadmin-btn-tags" data-type="modifyprice">修改金额</button>
                        }
                        <button class="layui-btn layui-btn-danger layuiadmin-btn-tags" data-type="deleteorder">删除订单</button>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

